package com.hisoft.traffic.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hisoft.traffic.pojo.Team;
import com.hisoft.traffic.service.TeamService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: traffic
 * @description:
 * @author: wlg
 * @create: 2022-03-03 08:51:11
 **/
@Controller
@RequestMapping("/busTeam")
public class TeamController {

    @Resource
    private TeamService teamService;

    @PostMapping("/search")
    @ResponseBody
    public Object search(
            @RequestParam(value = "page",defaultValue = "1") Integer pageNo,
            @RequestParam(value = "rows",defaultValue = "10") Integer pageSize,
            @RequestParam(value = "teamName",required = false) String teamName){

        PageHelper.startPage(pageNo, pageSize);
        List<Team> teams = teamService.queryAllPageTeams(teamName);
        //用PageInfo对结果进行包装
        PageInfo page = new PageInfo(teams);
        Map<String,Object> map = new HashMap<>();
        map.put("rows",page.getList());
        map.put("total",page.getTotal());
        return map;
    }
}
